<template>
	<view>
		<!-- pages/rental/renting_list/renting_list.wxml -->

		<view class="container">
			<view class="center_slot">
				<view class="flex-box areas plr30">
					<navigator url="/pages/home/locate/locate" hover-class="none">
						<view class="city-picker flex-box flex-center">{{ now_city }}</view>
					</navigator>
					<!-- #ifndef MP -->
					<navigator url="/pages/home/search/search?jump_type=2" class="flex-box  flex-grow-1 mr30 inputbox">
						<image src="/static/icon/h-icon_sou.png" class="icon_search"></image>
						<input disabled :value="searchCheckJson.keyword" class="fs22 flex-grow-1" placeholder="请输入你要查找的内容"></input>
						<image src="/static/icon/close.png" class="icon_direct"  v-if="searchCheckJson.keyword"  style="width:40rpx;height:40rpx" @tap.stop.prevent="delKeywords"></image>
					</navigator>
					<!-- #endif -->
					<!-- #ifdef MP -->
					<navigator url="/pages/home/search/search?jump_type=2" class="flex-box  flex-grow-1 mr30 inputbox" style="width: 350rpx;">
						<image src="/static/icon/h-icon_sou.png" class="icon_search"></image>
						<input disabled :value="searchCheckJson.keyword" class="fs22 flex-grow-1" placeholder="请输入你要查找的内容"></input>
						<image src="/static/icon/close.png" class="icon_direct"  v-if="searchCheckJson.keyword"  style="width:40rpx;height:40rpx" @tap.stop.prevent="delKeywords"></image>
					</navigator>
					<!-- #endif -->
					<!-- #ifndef H5 -->
					<navigator url="/pages/home/map_search/map_search?tabIdx=1" hover-class="none" class="tc">
						<image src="/static/icon/h-icon_map.png" class="icon_map" mode=""></image>
						<view class="fs20 col10">地图找房</view>
					</navigator>
					<!-- #endif -->
				</view>
				<view class="flex-box sortbox">
					<view
						:class="'sortitem ' + (regionStatus || searchCheckJson.nearby || searchCheckJson.region || searchCheckJson.subway_id ? 'active' : '')"
						@tap="openarea">
						区域
					</view>
					<view
						:class="'sortitem ' + (priceStatus || searchCheckJson.max_average_price || searchCheckJson.max_total_price ? 'active' : '')"
						@tap="openprice">价格</view>
					<!-- <view :class="'sortitem ' + (houseStatus || searchCheckJson.search_roomnum_ids != '' ? 'active' : '')" @tap="openhouse">户型</view> -->
					<view :class="'sortitem ' + (rentalModeStatus || searchCheckJson.rental_mode_id != '' ? 'active' : '')" @tap="openRentalMode">类型</view>
					<view :class="'sortitem ' + (moreStatus || searchCheckJson.sale_state || searchCheckJson.type_ids || searchCheckJson.developer_ids ? 'active' : '')" @tap="openmore">更多</view>
				</view>
			</view>
			<view class="houselist">
				<template v-if="houseList.total > 0">
					<navigator class="houseitem df" :url="'/pages/rental/renting/renting?id=' + item.id"
						v-for="(item, index) in houseList.data">
						<image :src="item.image_text" class="houseimg" mode="aspectFill"></image>

						<view class="flex-grow-1">
							<view class="df ac">
								<view class="housename single-line flex-grow-1">{{ item.name }}</view>
							</view>
							<view class="area-size">
								<text>{{ item.village2.region }}</text>
								<text>{{ item.space }}㎡</text>
							</view>
							<view class="targetbox df flexwa">
								<view class="targetitem" v-for="(targets, index1) in item.house_tag_ids_text_arr">
									{{ targets.tag.name }}
								</view>
							</view>
							<view class="housecost">
								¥
								<text>{{ item.price }}</text>
								/月
							</view>
							<!-- <view class="df ac event" wx:if='{{item.guarantee}}'>
							<view class="bao">保</view>
							<view class="fs18">低价保障，买贵就赔差价</view>
						</view>
						<view class="df ac event" wx:if='{{item.event}}'>
							<view class="dong">动</view>
							<view class="fs18">项目住宅产品在售</view>
						</view> -->
						</view>
					</navigator>
					<template v-if="houseList.current_page >= houseList.last_page && houseList.total > 5">
						<view class="fs30 col9 tc">数据加载完毕</view>
					</template>
				</template>
				<template v-else>
					<image :lazy-load="true" src="/static/images/none-data.png" class="none-data-style">
					</image>
					<view class="fs28 col9 tc">暂无数据</view>
				</template>
			</view>
		</view>
		<!-- </scroll-view> -->

		<!-- 选择区域 -->
		<u-popup :show="regionStatus" mode="top" @close="closepopup" :safeAreaInsetBottom="false">
			<view class="pricewrap" style="padding-top: 178rpx;">
				<view class="flex-box">
					<view class="singleprice">
						<view @tap="choosesearchtype" data-type="1"
							:class="'price-left ' + (search_type == 1 ? 'active' : '')">区域</view>
						<view v-if="subwayData.length > 0" @tap="choosesearchtype" data-type="2"
							:class="'price-left ' + (search_type == 2 ? 'active' : '')">地铁</view>
						<view @tap="choosesearchtype" data-type="3"
							:class="'price-left ' + (search_type == 3 ? 'active' : '')">附近</view>
					</view>
					<template v-if="search_type == 1">
						<scroll-view scroll-y="true" :class="'rangeprice '+(now_area_index > 0?'leftline':'')">
							<view :class="'price-right ' + (now_area_index == 0 ? 'active' : '')" @tap="chooseregion"
								data-index="0">不限</view>
							<template v-for="(item, index) in areaData">
								<view
									:class="'price-right single-line ' + (now_area_index - 1 == index ? 'active' : '')"
									@tap="chooseregion" :data-index="index + 1">
									{{ item.name }}
								</view>
							</template>
						</scroll-view>
						<scroll-view scroll-y="true" v-if="now_area_index > 0" class="rangeprice rightline">
							<view :class="'price-right ' + (searchCheckJson.street == '' ? 'active' : '')"
								@tap="choosestreet" data-index="0">不限</view>
							<template v-for="(item, index) in nowStreetData">
								<view
									:class="'price-right single-line ' + (searchCheckJson.street == item.name ? 'active' : '')"
									@tap="choosestreet" :data-index="index + 1">
									{{ item.name }}
								</view>
							</template>
						</scroll-view>
					</template>
					<template v-else-if="search_type == 2">
						<scroll-view scroll-y="true" :class="'rangeprice '+(now_subway_index > 0?'leftline':'')">
							<view :class="'price-right ' + (now_subway_index == 0 ? 'active' : '')" @tap="choosesubway"
								data-index="0">不限</view>
							<template v-for="(item, index) in subwayData">
								<view
									:class="'price-right single-line ' + (now_subway_index - 1 == index ? 'active' : '')"
									@tap="choosesubway" :data-index="index + 1">{{ item.name }}</view>
							</template>
						</scroll-view>
						<scroll-view scroll-y="true" v-if="now_subway_index > 0" class="rangeprice rightline">
							<view
								:class="'price-right single-line ' + (searchCheckJson.subway_platform_id ? '' : 'active')"
								@tap="chooseplatform" data-index="0">不限</view>
							<template v-for="(item, index) in nowPlatformData">
								<view
									:class="'price-right single-line ' + (searchCheckJson.subway_platform_id == item.id ? 'active' : '')"
									@tap="chooseplatform" :data-index="index + 1">
									{{ item.name }}
								</view>
							</template>
						</scroll-view>
					</template>
					<template v-else-if="search_type == 3">
						<scroll-view scroll-y="true" class="rangeprice">
							<view :class="'price-right ' + (searchCheckJson.nearby ? '' : 'active')" @tap="choosenearby"
								data-nearby="0">不限</view>
							<view :class="'price-right ' + (searchCheckJson.nearby == 1 ? 'active' : '')"
								@tap="choosenearby" data-nearby="1">1km</view>
							<view :class="'price-right ' + (searchCheckJson.nearby == 2 ? 'active' : '')"
								@tap="choosenearby" data-nearby="2">2km</view>
							<view :class="'price-right ' + (searchCheckJson.nearby == 3 ? 'active' : '')"
								@tap="choosenearby" data-nearby="3">3km</view>
						</scroll-view>
					</template>
				</view>
			</view>
		</u-popup>
		<!-- 选择价格 -->
		<u-popup :show="priceStatus" mode="top" :safeAreaInsetBottom="false" @close="closepopup">
			<view class="pricewrap" style="padding-top: 178rpx;">

				<view class="flex-box">

					<scroll-view v-if="is_single" scroll-y="true" class="rangeprice" style="width: 100%;">
						<template v-for="(item, index) in searchData.priceData">
							<view v-if="item.type == 1" :class="'price-right ' + (item.is_choose ? 'active' : '')"
								:data-index="index" @tap="chooseprice">{{ item.name }}</view>
						</template>
					</scroll-view>
					<scroll-view v-else scroll-y="true" class="rangeprice" style="width: 100%;">
						<template v-for="(item, index) in searchData.priceData">
							<view v-if="item.type == 2" :class="'price-right ' + (item.is_choose ? 'active' : '')"
								:data-index="index" @tap="chooseprice">{{ item.name }}</view>
						</template>
					</scroll-view>
				</view>
				<view class="flex-box flex-center inputrange">
					<view v-if="is_single" class="flex-box">
						<input class="fs30" @input="min_priceFun" :value="min_price" type="digit" v-if="priceStatus"
							placeholder="最小" />
						<view class="line">-</view>
						<input class="fs30" @input="max_priceFun" :value="max_price" type="digit" v-if="priceStatus"
							placeholder="最大" />
						<view class="wan">元</view>
					</view>
					<view v-else class="flex-box">
						<input class="fs30" @input="min_total_price_fuc" :value="min_total_price" type="digit"
							v-if="priceStatus" placeholder="最小" />
						<view class="line">-</view>
						<input class="fs30" @input="max_total_price_fuc" :value="max_total_price" type="digit"
							v-if="priceStatus" placeholder="最大" />
						<view class="wan">元</view>
					</view>
					<button class="sure" @tap="confirmprice">确定</button>
				</view>

			</view>


		</u-popup>
		<!-- 选择户型 -->
		<!-- <u-popup :show="houseStatus" mode="top" @close="closepopup" :safeAreaInsetBottom="false">
			<view class="housewrap" style="padding-top: 178rpx;">
				<scroll-view scroll-y="true" class="checkgroup">
					<view class="flex-box  flex-between checkitem fs30" @tap="chooseroomnum" :data-index="index"
						v-for="(item, index) in searchData.roomnumData">
						<view :class="item.is_choose ? 'col009' : ''">{{ item.name }}</view>
						<image :src="'/static/icon/icon_choose' + (item.is_choose ? '-on' : '') + '.png'"
							class="choose"></image>
					</view>
				</scroll-view>
				<view class="flex-box  flex-between btuttons">
					<button hover-class="none" class="btn1" @tap="clearroomnum">清空</button>
					<button hover-class="none" class="btn2" @tap="confirmroomnum">确定</button>
				</view>
			</view>
		</u-popup> -->

		<!-- 租赁类型 -->
		<u-popup :show="rentalModeStatus" mode="top" @close="closepopup" :safeAreaInsetBottom="false">
			<view class="housewrap" style="padding-top: 178rpx;">
				<scroll-view scroll-y="true" class="checkgroup">
					<view class="flex-box  flex-between checkitem fs30" @tap="chooseRentalMode" :data-index="index" v-for="(item, index) in searchData.rentalMode">
						<view :class="item.is_choose ? 'col009' : ''">{{ item.name }}</view>
						<image :src="'/static/icon/icon_choose' + (item.is_choose ? '-on' : '') + '.png'"
							class="choose"></image>
					</view>
				</scroll-view>
				<view class="flex-box  flex-between btuttons">
					<button hover-class="none" class="btn1" @tap="clearRentalMode">清空</button>
					<button hover-class="none" class="btn2" @tap="confirmRentalMode">确定</button>
				</view>
			</view>
		</u-popup>
		
		
		

		<!-- 选择更多 -->
		<u-popup :show="moreStatus" mode="top" @close="closepopup" :safeAreaInsetBottom="false">
			<view class="morewrap" style="padding-top: 178rpx;">

				<scroll-view scroll-y="true" class="morebox">
					<view class="moreitem">
						<view class="moretitle">
							类型
							<text>（可多选）</text>
						</view>
						<view class="flex-box flex-wrap">

							<view :data-index="index" @tap="choosetype"
								:class="'items ' + (item.is_choose ? 'active' : '')"
								v-for="(item, index) in searchData.typeData">
								{{ item.name }}
							</view>
						</view>

					</view>
					
					<view class="moreitem">
						<view class="moretitle">
							户型
							<text>（可多选）</text>
						</view>
						<view class="flex-box flex-wrap">
									
							<view :data-index="index" @tap="chooseroomnum"
								:class="'items ' + (item.is_choose ? 'active' : '')"
								v-for="(item, index) in searchData.roomnumData">
								{{ item.name }}
							</view>
						</view>
									
					</view>
				</scroll-view>
				
				<view class="df ac js btuttons">
					<button class="btn1" @tap="clearmore">清空</button>
					<button class="btn2" @tap="confirmmore">确定</button>
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script module="inarr" lang="wxs">
	function is_in_array(id, str) {
		if (str) {
			var arr = str.split(',');
			if (arr.indexOf(id) != -1) {
				return true;
			}
		}
		return false;
	}
	module.exports.is_in_array = is_in_array;
</script>
<script>
	//
	const app = getApp();

	const functions = require('../../../utils/functions.js');

	export default {
		data() {
			return {
				// 当前城市
				now_city: '上海市',

				// 城市其下区县、街道
				areaData: [],

				// 城市其下地铁数据
				subwayData: [],

				// 房源搜索条件
				searchData: {
					priceData: [],

					//获取搜索价格
					roomnumData: [],
					
					//房源类型
					rentalMode:[],

					//获取搜索户型
					typeData: [],

					//类型
					//tag标签
					tagData: [],

					village_id: '',
					developerData: ''
				},

				// 房源列表
				houseList: {
					total: 0,
					current_page: 0,
					last_page: 1,
					data: []
				},

				// 已选中的搜索条件
				searchCheckJson: {
					region: '',

					//区域
					street: '',

					//街道/镇
					keyword: '',

					//搜索关键词
					lat: '',

					//纬度
					lng: '',

					//经度
					nearby: '',

					//附近几公里
					subway_id: '',

					//地铁线id
					subway_platform_id: '',

					//地铁站id
					min_price: '',

					//最小单价（万元）
					max_price: '',

					//最大单价（万元）（-1为无限大）
					search_roomnum_ids: '',
					
					//类型
					rental_mode_id:'',

					//查询户型(多个id用英文逗号隔开)
					type_ids: '',

					//查询类型(多个id用英文逗号隔开)
					tag_ids: '',

					//查询标签(多个id用英文逗号隔开)
					village_id: 0,

					//排序:1=默认排序，2=看房次数从大到小（人气排行榜），3=单价从小到大，4=单价从大到小，5=成交量从大到小(热销排行榜)
					sort: 1,

					sale_state: '',
					developer_ids: '',
					min_total_price: '',
					max_total_price: ''
				},

				choose_sale_state: '',

				//当前选中的售卖情况
				is_single: true,

				min_price: '',
				max_price: '',
				min_total_price: '',
				max_total_price: '',
				search_type: 1,

				//区域弹窗点开，选择类型:1=区域，2=地铁，3=附近
				now_area_index: 0,

				nowStreetData: [],
				now_subway_index: 0,
				nowPlatformData: [],
				village_name: '',
				regionStatus: false,
				priceStatus: false,
				houseStatus: false,
				rentalModeStatus:false,
				moreStatus: false,
				triggered: false,
				targets: []
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			this.searchData.village_id = options.village_id || 0;
			this.village_name = options.village_name || '';


			if (options.village_name) {
				uni.setNavigationBarTitle({
					title: options.village_name
				});
			}

			if (!app.globalData.is_need_page_change) {
				this.initData();
			}
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			if (app.globalData.is_need_page_change) {
				var param = app.globalData.pagesParam;
				app.globalData.is_need_page_change = false;

				if (param.keyword) {
					this.searchCheckJson.keyword = param.keyword;

				}

				if (param.sale_state) {
					this.choose_sale_state = param.sale_state;
					this.searchCheckJson.sale_state = param.sale_state;

				}

				if (param.type_id) {
					var typeData = this.searchData.typeData;

					for (let index = 0; index < typeData.length; index++) {
						if (typeData[index].id == param.type_id) {
							typeData[index].is_choose = true;
						} else {
							typeData[index].is_choose = false;
						}
					}

					this.searchData.typeData = typeData;
					this.searchCheckJson.type_ids = param.type_id;

				}

				if (param.tag_id) {
					var tagData = this.searchData.tagData;

					for (let index = 0; index < tagData.length; index++) {
						if (tagData[index].id == param.tag_id) {
							tagData[index].is_choose = true;
						} else {
							tagData[index].is_choose = false;
						}
					}

					this.searchData.tagData = tagData;
					this.searchCheckJson.tag_ids = param.tag_id;
				}
				if(param.rental_mode_id){
					var rentalMode = this.searchData.rentalMode;
					for(let i=0;i<rentalMode.length;i++){
						if (rentalMode[i].id == param.rental_mode_id) {
							rentalMode[i].is_choose = true;
						} else {
							rentalMode[i].is_choose = false;
						}
					}
					this.searchData.rentalMode = rentalMode;
					this.searchCheckJson.rental_mode_id = param.rental_mode_id;
				}

				if (param.keyword || param.sale_state || param.type_id || param.tag_id || param.rental_mode_id) {
					this.houseList.current_page = 0;
					// 获取该城市的房源列表

					this.getHouseList();
				}
			}

			var now_city = uni.getStorageSync('now_city') || '上海市';

			if (now_city != this.now_city) {
				this.initData();
			}
			
			app.setMessageBadge(false)
		},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {
			if (this._freshing) {
				return;
			}

			this._freshing = true; // wx.showNavigationBarLoading() //在标题栏中显示加载

			var that = this; //模拟加载

			setTimeout(function() {
				that.initData();
				that.triggered = false;
				that._freshing = false; // wx.stopPullDownRefresh() //停止下拉刷新
			}, 1500);
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		// onShareAppMessage: function () {
		// }
		onReachBottom: function() {
			if (this.houseList.current_page >= this.houseList.last_page) {
				this.loadStatus = 'nomore';
				return false;
			} else {
				this.getHouseList();
			}
		},
		/**
		 * 用户点击右上角分享
		 */
		methods: {
			delKeywords() {
				this.searchCheckJson.keyword = '';
				this.houseList.current_page = 0;
				// 获取该城市的房源列表

				this.getHouseList();
			},

			//关闭弹窗
			closepopup() {
				this.regionStatus = false;
				this.priceStatus = false;
				this.houseStatus = false;
				this.rentalModeStatus = false;
				this.moreStatus = false;

			},

			// 跳转页面 type=1(跳转有tabBar底部的页面)，type=2(正常跳转)
			jumpPages(event) {
				var type = Number(event.currentTarget.dataset.type);
				var url = event.currentTarget.dataset.url;

				if (type == 1) {
					uni.switchTab({
						url: url
					});
				} else {
					uni.navigateTo({
						url: url
					});
				}
			},

			//省市区弹窗
			openarea() {
				this.regionStatus = !this.regionStatus;
				this.priceStatus = false;
				this.houseStatus = false;
				this.rentalModeStatus = false;
				this.moreStatus = false;

			},

			//价格弹窗
			openprice() {
				this.priceStatus = !this.priceStatus;
				this.regionStatus = false;
				this.houseStatus = false;
				this.rentalModeStatus = false;
				this.moreStatus = false;

			},
			//户型弹窗
			// openhouse() {
			// 	this.houseStatus = !this.houseStatus;
			// 	this.priceStatus = false;
			// 	this.regionStatus = false;
			// 	this.moreStatus = false;

			// },
			//租赁模式弹窗
			openRentalMode() {
				this.rentalModeStatus = !this.rentalModeStatus;
				this.priceStatus = false;
				this.regionStatus = false;
				this.moreStatus = false;

			},

			//更多弹窗
			openmore() {
				this.moreStatus = !this.moreStatus;
				this.regionStatus = false;
				this.priceStatus = false;
				this.houseStatus = false;
				this.rentalModeStatus = false;
			},

			// 选择tag
			checkTags(event) {
				var type = Number(event.currentTarget.dataset.type);
				var id = event.currentTarget.dataset.id + '';
				var tag_ids = this.searchCheckJson.tag_ids;
				var tag_arr = tag_ids ? tag_ids.split(',') : [];
				var i = tag_arr.indexOf(id);

				if (i == -1) {
					tag_arr.push(id);
				} else {
					tag_arr.splice(i, 1);
				}

				tag_ids = tag_arr.join(',');
				this.searchCheckJson.tag_ids = tag_ids;
				this.houseList.current_page = 0;
				// 获取该城市的房源列表

				this.getHouseList();
				this.handleCheckedDataShow();
			},

			//选择户型
			chooseroomnum(event) {
				var index = event.currentTarget.dataset.index;
				var roomnumData = this.searchData.roomnumData
				roomnumData[index].is_choose = !roomnumData[index].is_choose
				this.searchData.roomnumData = roomnumData

			},
			//选择类型
			chooseRentalMode(event) {
				var index = event.currentTarget.dataset.index;
				var rentalMode = this.searchData.rentalMode;
				for(let i=0;i<rentalMode.length;i++){
					rentalMode[i].is_choose = false;
				}
				rentalMode[index].is_choose = !rentalMode[index].is_choose;
				this.searchData.rentalMode = rentalMode;
			},
			// 清空租赁模式
			clearRentalMode() {
				var rentalMode = this.searchData.rentalMode;

				for (let index = 0; index < rentalMode.length; index++) {
					rentalMode[index].is_choose = false;
				}

				this.searchCheckJson.rental_mode_id = '';
				this.searchData.rentalMode = rentalMode;
				this.houseList.current_page = 0;
				// 获取该城市的房源列表
				this.getHouseList();
				this.openRentalMode();
			},
			
			// 确认租赁模式
			confirmRentalMode() {
				var rentalMode = this.searchData.rentalMode;
				let rental_mode_id = 0;
				for (var i = 0; i < rentalMode.length; i++) {
					if(rentalMode[i].is_choose){
						rental_mode_id = rentalMode[i].id
					}
				}
				this.searchCheckJson.rental_mode_id = rental_mode_id;
				this.houseList.current_page = 0;
				// 获取该城市的房源列表
				this.getHouseList();
				this.openRentalMode();
			},

			// 选择类型
			choosetype(event) {
				var index = event.currentTarget.dataset.index;
				var typeData = this.searchData.typeData;
				typeData[index].is_choose = !typeData[index].is_choose;
				this.searchData.typeData = typeData;
			},

			// 选择售卖情况
			choosesalestate(event) {
				var type = event.currentTarget.dataset.type;
				this.choose_sale_state = type;

			},

			// 选择开发商
			choosedeveloper(event) {
				var index = event.currentTarget.dataset.index;
				var developerData = this.searchData.developerData;
				developerData[index].is_choose = !developerData[index].is_choose;
				this.searchData.developerData = developerData;

			},

			// 清空更多选择
			clearmore() {
				var searchData = this.searchData;

				for (let index = 0; index < searchData.typeData.length; index++) {
					searchData.typeData[index].is_choose = false;
				}
				
				
				for (let index = 0; index < searchData.roomnumData.length; index++) {
					searchData.roomnumData[index].is_choose = false;
				}


				this.searchCheckJson.type_ids = '';
				this.searchCheckJson.search_roomnum_ids = '';
				this.searchCheckJson.developer_ids = '';
				this.searchCheckJson.sale_state = '';
				this.choose_sale_state = '';
				this.searchData = searchData;
				this.houseList.current_page = 0;
				// 获取该城市的房源列表

				this.getHouseList();
				this.openmore();
			},

			// 确认更多选择
			confirmmore() {
				var typeData = this.searchData.typeData;
				var type_ids_arr = [];

				for (let index = 0; index < typeData.length; index++) {
					if (typeData[index].is_choose) {
						type_ids_arr.push(typeData[index].id);
					}
				}
				let roomnumData = this.searchData.roomnumData;
				let search_roomnum_ids = [];
				for (let index = 0; index < roomnumData.length; index++) {
					if (roomnumData[index].is_choose) {
						search_roomnum_ids.push(roomnumData[index].id);
					}
				}

				this.searchCheckJson.type_ids = type_ids_arr ? type_ids_arr.join(',') : '';
				this.searchCheckJson.search_roomnum_ids = search_roomnum_ids.length>0 ? search_roomnum_ids.join(',') : '';
				this.houseList.current_page = 0;
				// 获取该城市的房源列表

				this.getHouseList();
				this.openmore();
			},

			//选择单价还是总价
			chooseissingle() {
				this.setData({
					is_single: !this.is_single
				});
			},

			// 选择单价或总价
			chooseprice(event) {
				var index = event.currentTarget.dataset.index;
				var priceData = this.searchData.priceData;

				if (priceData[index].type == 1) {
					for (let i = 0; i < priceData.length; i++) {
						if (priceData[i].type == 1) {
							priceData[i].is_choose = false;
						}
					}

					this.min_price = '';
					this.max_price = '';
					this.searchCheckJson.min_price = priceData[index].min_price;
					//最小单价（万元）
					this.searchCheckJson.max_price = priceData[index].max_price; //最大单价（万元）（-1为无限大）

				} else {
					for (let i = 0; i < priceData.length; i++) {
						if (priceData[i].type == 2) {
							priceData[i].is_choose = false;
						}
					}

					this.min_total_price = '';
					this.max_total_price = '';
					this.searchCheckJson.min_total_price = priceData[index].min_price;
					//最小总价（万元）
					this.searchCheckJson.max_total_price = priceData[index].max_price; //最大总价（万元）（-1为无限大）

				}

				priceData[index].is_choose = !priceData[index].is_choose;
				this.searchData.priceData = priceData;
				this.houseList.current_page = 0;
				// 获取该城市的房源列表

				this.getHouseList();
				this.openprice();
			},

			min_priceFun(e) {
				this.min_price = e.detail.value

			},

			max_priceFun(e) {
				this.max_price = e.detail.value

			},

			min_total_priceFun(e) {
				this.min_total_price = e.detail.value

			},

			max_total_priceFun(e) {
				this.max_total_price = e.detail.value

			},

			// 确认价格搜索
			confirmprice() {
				if (this.is_single && (!this.min_price || !this.max_price || this.min_price > this.max_price)) {
					functions.toast('请输入正确的价格');
					return false;
				}

				if (!this.is_single && (!this.min_total_price || !this.max_total_price || this.min_total_price > this
						.max_total_price)) {
					functions.toast('请输入正确的价格');
					return false;
				}

				var priceData = this.searchData.priceData;

				if (this.is_single) {
					for (let i = 0; i < priceData.length; i++) {
						if (priceData[i].type == 1) {
							priceData[i].is_choose = false;
						}
					}

					this.searchCheckJson.min_price = this.min_price;
					//最小单价（万元）
					this.searchCheckJson.max_price = this.max_price; //最大单价（万元）（-1为无限大）

				} else {
					for (let i = 0; i < priceData.length; i++) {
						if (priceData[i].type == 2) {
							priceData[i].is_choose = false;
						}
					}

					this.searchCheckJson.min_total_price = this.min_total_price;
					//最小单价（万元）
					this.searchCheckJson.max_total_price = this.max_total_price //最大单价（万元）（-1为无限大）

				}

				this.searchData.priceData = priceData;
				this.houseList.current_page = 0;
				// 获取该城市的房源列表

				this.getHouseList();
				this.openprice();
			},

			// 选择区域搜索类型
			choosesearchtype(event) {
				var type = event.currentTarget.dataset.type;
				this.search_type = type

			},

			// 选择附近
			choosenearby(event) {
				var nearby = event.currentTarget.dataset.nearby;
				this.searchCheckJson.nearby = nearby;
				this.houseList.current_page = 0;
				// 获取该城市的房源列表

				this.getHouseList();
				this.openarea();
			},

			// 选择区域
			chooseregion(event) {
				var index = event.currentTarget.dataset.index;
				var areaData = this.areaData;

				if (index == 0) {
					this.now_area_index = index;
					this.searchCheckJson.region = '';
					this.searchCheckJson.street = '';
					this.houseList.current_page = 0;
					// 获取该城市的房源列表

					this.getHouseList();
					this.openarea();
				} else {
					this.now_area_index = index;
					this.nowStreetData = areaData[index - 1].list;

				}
			},

			// 选择街道
			choosestreet(event) {
				var index = event.currentTarget.dataset.index;
				var areaData = this.areaData;
				var nowStreetData = this.nowStreetData;

				if (index == 0) {
					this.searchCheckJson.region = areaData[this.now_area_index - 1].name;
					this.searchCheckJson.street = '';
					this.houseList.current_page = 0;

				} else {
					this.searchCheckJson.region = areaData[this.now_area_index - 1].name;
					this.searchCheckJson.street = nowStreetData[index - 1].name;
					this.houseList.current_page = 0;

				} // 获取该城市的房源列表

				this.getHouseList();
				this.openarea();
			},

			// 选择地铁线
			choosesubway(event) {
				var index = event.currentTarget.dataset.index;
				var subwayData = this.subwayData;

				if (index == 0) {
					this.now_subway_index = index;
					this.searchCheckJson.subway_id = 0;
					this.searchCheckJson.subway_platform_id = 0;
					this.houseList.current_page = 0;
					// 获取该城市的房源列表

					this.getHouseList();
					this.openarea();
				} else {
					this.now_subway_index = index;
					this.nowPlatformData = subwayData[index - 1].list;

				}
			},

			// 选择地铁站
			chooseplatform(event) {
				var index = event.currentTarget.dataset.index;
				var subwayData = this.subwayData;
				var nowPlatformData = this.nowPlatformData;

				if (index == 0) {
					this.searchCheckJson.subway_id = subwayData[this.now_subway_index - 1].id;
					this.searchCheckJson.subway_platform_id = 0;
					this.houseList.current_page = 0;

				} else {
					this.searchCheckJson.subway_id = subwayData[this.now_subway_index - 1].id;
					this.searchCheckJson.subway_platform_id = nowPlatformData[index - 1].id;
					this.houseList.current_page = 0;

				} // 获取该城市的房源列表

				this.getHouseList();
				this.openarea();
			},

			doSearch(e) {
				this.searchCheckJson.keyword = e.detail.value;
				this.houseList.current_page = 0;
				// 获取该城市的房源列表

				this.getHouseList();
			},

			// 处理已选数据
			handleCheckedDataShow: function(searchData) {
				var tagData = searchData.tagData;
				var tag_ids = this.searchCheckJson.tag_ids;
				var tag_arr = tag_ids ? tag_ids.split(',') : [];

				for (let index = 0; index < tagData.length; index++) {
					const element = tagData[index];
					var id = element.id + '';

					if (tag_arr.indexOf(id) == -1) {
						tagData[index].is_choose = false;
					} else {
						tagData[index].is_choose = true;
					}
				}

				searchData.tagData = tagData; // 处理户型

				var roomnumData = searchData.roomnumData;
				var search_roomnum_ids = this.searchCheckJson.search_roomnum_ids;
				var search_roomnum_arr = search_roomnum_ids ? search_roomnum_ids.split(',') : [];

				for (let index = 0; index < roomnumData.length; index++) {
					const element = roomnumData[index];
					var id = element.id + '';

					if (search_roomnum_arr.indexOf(id) == -1) {
						roomnumData[index].is_choose = false;
					} else {
						roomnumData[index].is_choose = true;
					}
				}

				searchData.roomnumData = roomnumData; // 处理类型
				
				//租赁类型
				var rentalMode = searchData.rentalMode;
				for (let index = 0; index < rentalMode.length; index++) {
					rentalMode[index].is_choose = false;
				}
				searchData.rentalMode = rentalMode;

				var typeData = searchData.typeData;
				var type_ids = this.searchCheckJson.type_ids;
				var type_arr = type_ids ? type_ids.split(',') : [];

				for (let index = 0; index < typeData.length; index++) {
					const element = typeData[index];
					var id = element.id + '';

					if (type_arr.indexOf(id) == -1) {
						typeData[index].is_choose = false;
					} else {
						typeData[index].is_choose = true;
					}
				}

				searchData.typeData = typeData; // 处理价格

				var priceData = searchData.priceData;

				for (let index = 0; index < priceData.length; index++) {
					priceData[index].is_choose = false;
				}

				searchData.priceData = priceData;
				this.searchData = searchData;

			},

			// 获取房源列表信息
			getHouseList: function() {
				var that = this;
				var json = {
					city: that.now_city
				};
				json.page = Number(that.houseList.current_page) + 1;
				Object.assign(json, this.searchCheckJson);

				if (json.page > 1 && that.houseList.current_page >= that.houseList.last_page) {
					functions.toast('已加载到底部了');
					this.loadStatus = 'nomore';
					return false;
				} // 其他搜索条件
				// 。。。
				this.loadStatus = 'loading';
				functions.getAjaxList(that, '/api/xiluhouse/rental/house_list', json, function(res) {
					var houseList = res.data;

					if (json.page > 1) {
						var now_houseList_data = that.houseList.data || [];
						var now_houseList_data = now_houseList_data.concat(houseList.data);
						houseList.data = now_houseList_data;
					}
					console.log(houseList)
					that.houseList = houseList;

				});
			},

			// 获取所有可下拉刷新更新的数据
			initData: function() {
				var that = this;
				var now_city = uni.getStorageSync('now_city');
				this.now_city = now_city ? now_city : '上海市'

				// 获取---通用类-城市下区县、街道

				functions.getAjaxData(
					'/api/xiluhouse/universal/region_street_data', {
						city: that.now_city
					},
					function(res) {
						that.areaData = res.data

					}
				); // 获取---通用类-根据城市获取当前地铁数据

				functions.getAjaxData(
					'/api/xiluhouse/universal/subways_data', {
						city: that.now_city
					},
					function(res) {
						that.subwayData = res.data

					}
				); // 获取---通用类-房源类型搜索数据

				functions.getAjaxData(
					'/api/xiluhouse/universal/search_field_data2', {
						city: that.now_city
					},
					function(res) {
						// that.searchData = res.data

						that.handleCheckedDataShow(res.data);
					}
				);
				that.houseList.current_page = 0
				// 获取该城市的房源列表

				that.getHouseList();
			}
		}
	};
</script>
<style scoped lang="scss">
	@import url('@/static/css/old_project.css');

	/* pages/building_list/building_list.wxss */
	.pricewrap .rangeprice.leftline {
		width: 285rpx
	}

	.pricewrap .rangeprice.rightline {
		width: 285rpx;
		background-color: #fff
	}
	
	.icon_map {
		width: 31rpx;
		height: 39rpx;
	}

	// .pricewrap .rangeprice{
	// 	width: 100%;
	// }
	.center_slot {
		width: 100vw;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 99999;
		background-color: var(--white);
	}

	.sortbox {
		// position: sticky;
		height: 90rpx;
		line-height: 90rpx;
		border-bottom: 1px solid #f4f3f3;
		// top: calc(var(--status-bar-height) + 88upx);
		background-color: var(--white);
		z-index: 9999999;
	}

	.sortbox .sortitem {
		flex: 1;
		align-items: center;
		justify-content: center;
		display: flex;
	}

	.sortbox .sortitem::after {
		width: 0;
		content: "";
		display: block;
		height: 0;
		margin-left: 14rpx;
		border-top: 8rpx solid #ccc;
		border-right: 7.5rpx solid transparent;
		border-bottom: 0 solid transparent;
		border-left: 7.5rpx solid transparent;

	}

	.sortbox .sortitem.active {
		color: var(--normal);
	}

	.sortbox .sortitem.active::after {
		width: 0;
		content: "";
		display: block;
		height: 0;
		margin-left: 14rpx;
		border-top: 0 solid transparent;
		border-right: 7.5rpx solid transparent;
		border-bottom: 8rpx solid var(--normal);
		border-left: 7.5rpx solid transparent;
	}

	.typelist {
		white-space: nowrap;
		overflow-x: scroll;
		width: 100%;
		padding: 30rpx 0 30rpx;
	}

	.typelist view {
		padding: 10rpx 25rpx;
		border-radius: 5px;
		background: #f6f7fa;
		color: #898989;
		display: inline-block;
		margin-right: 20rpx;
	}

	.typelist view.active {
		background-color: #0091ff;
		color: #fff;
	}

	.typelist view:first-child {
		margin-left: 40rpx;
	}

	.houselist {
		padding: 220rpx 40rpx 0;
	}

	.houselist .houseitem {
		padding-bottom: 30rpx;
	}

	.houselist .houseitem .houseimg {
		width: 240rpx;
		height: 190rpx;
		border-radius: 10rpx;
		margin-right: 20rpx;
	}

	.houselist .housename {
		font-size: 30rpx;
		padding-bottom: 10rpx;
	}

	.houselist .area-size {
		font-size: 24rpx;
		color: #898989;
	}

	.houselist .area-size text:first-child {
		margin-right: 100rpx;
	}

	.houselist .targetbox {
		padding: 14rpx 0 0;
	}

	.houselist .targetitem {
		padding: 2rpx 4rpx;
		background: #cce9ff;
		font-size: 18rpx;
		color: #0091ff;
		border-radius: 2rpx;
		margin-right: 10rpx;
		margin-bottom: 12rpx;
	}

	.houselist .housecost {
		color: #f8532f;
		font-size: 24rpx;
	}

	.houselist .housecost text {
		font-size: 34rpx;
	}

	.houselist .event {
		padding-top: 11rpx;
		font-size: 18px;
		color: #898989;
	}

	.houselist .event .bao {
		width: 26rpx;
		text-align: center;
		line-height: 26rpx;
		font-size: 18rpx;
		height: 26rpx;
		border-radius: 5rpx;
		background: linear-gradient(180deg, #00c4ff, #0091ff);
		color: #fff;
		margin-right: 10rpx;
	}

	.houselist .event .dong {
		width: 26rpx;
		text-align: center;
		line-height: 26rpx;
		font-size: 18rpx;
		height: 26rpx;
		border-radius: 5rpx;
		background: linear-gradient(270deg, #ff6635, #ffb45c);
		color: #fff;
		margin-right: 10rpx;
	}

	.icon_direct {
		width: 28rpx;
		height: 28rpx;
	}

	.areas {
		z-index: 2;
		width: 100vw;
		height: 88rpx;
	}

	.city-picker {
		width: 150rpx;
		height: 70rpx;
		border-radius: 50rpx;
		background-color: rgba(255, 255, 255, 1);
		color: #010101;
		font-size: 24rpx;
		box-shadow: 0px 4rpx 30rpx rgba(184, 189, 202, 0.3);
	}

	.city-picker::after {
		width: 0;
		content: '';
		display: block;
		margin-top: 4rpx;
		margin-left: 15rpx;
		height: 0;
		border-top: 8rpx solid #ccc;
		border-right: 7.5rpx solid transparent;
		border-bottom: 8rpx solid transparent;
		border-left: 7.5rpx solid transparent;
	}

	.inputbox {
		width: 500rpx;
		height: 70rpx;
		border-radius: 50rpx;
		background-color: rgba(255, 255, 255, 1);
		color: #010101;
		margin-left: 20rpx;
		padding: 0 30rpx;
		box-shadow: 0px 4rpx 30rpx rgba(184, 189, 202, 0.3);
	}

	.icon_search {
		width: 30rpx;
		height: 30rpx;
		margin-right: 20rpx;
	}

	.inputbox input {
		color: #010101;
		font-size: 24rpx;
	}

	.fixtop {
		position: fixed;
		top: 120rpx;
		left: 0;
		right: 0;
		z-index: 999;
		background-color: #fff;
	}

	.areawrap {
		height: 550rpx;
		background-color: #fff;
	}

	.areawrap .areaitem {
		width: calc(100% / 3);
		height: 100%;
		overflow-y: scroll;
		text-align: center;
		font-size: 30rpx;
		background-color: #f6f7fa;
	}

	.areawrap .areaitem:nth-of-type(2) {
		background-color: #fff;
	}

	.areawrap .areaitem .items {
		line-height: 110rpx;
		height: 110rpx;
	}

	.areawrap .areaitem .items.active {
		color: #0091ff;
	}

	.housewrap {
		padding: 0 40rpx;
		background-color: #fff;
	}

	.housewrap .checkgroup {
		height: 420rpx;
		overflow-y: scroll;
	}

	.housewrap .choose {
		width: 30rpx;
		height: 30rpx;
	}

	.housewrap .btuttons {
		border-top: 1px solid #f4f3f3;
		height: 130rpx;
	}

	.housewrap .btuttons .btn1 {
		width: 320rpx;
		height: 80rpx;
		border-radius: 8rpx;
		border: solid 1rpx #cccccc;
		line-height: 80rpx;
		padding: 0;
		margin: 0;
		font-size: 30rpx;
		color: #777;
		font-weight: normal;
	}

	.housewrap .btuttons .btn2 {
		width: 320rpx;
		height: 80rpx;
		border-radius: 8rpx;
		line-height: 80rpx;
		padding: 0;
		margin: 0;
		font-size: 30rpx;
		color: #fff;
		font-weight: normal;
		background: #0091ff;
		box-shadow: 0px 4rpx 40rpx rgba(3, 103, 179, 0.3);
	}

	.housewrap .checkitem {
		height: 110rpx;
	}

	/* .container{overflow:hidden;height: 100vh;} */
	page {
		overflow: hidden;
	}

	.btnfix {
		position: fixed;
		bottom: 10%;
		right: 0;
		box-shadow: 0px 4rpx 40rpx rgba(3, 103, 179, 0.3);
		border-radius: 50rpx 0 0 50rpx;
	}

	.kefu-w {
		width: 32rpx;
		height: 35rpx;
		margin-right: 8rpx;
	}

	.tel-w {
		width: 32rpx;
		height: 31rpx;
		margin-right: 8rpx;
	}

	.btnfix .btn-kefu {
		padding: 0;
		margin: 0;
		width: 213rpx;
		height: 80rpx;
		line-height: 80rpx;
		border-radius: 50rpx 0 0 50rpx;
		background-color: #ff7b40;
		color: #fff;
		font-weight: normal;
	}

	.btnfix .btn-tel {
		padding: 0;
		margin: 0;
		width: 213rpx;
		height: 80rpx;
		line-height: 80rpx;
		background-color: #0091ff;
		color: #fff;
		border-radius: 0;
		font-weight: normal;
	}
</style>
